<?php
// No direct access to this file
defined('_JEXEC') or die('Restricted access');

// import Joomla view library
jimport('joomla.application.component.view');

class WmcReservationViewWmcReservation extends JViewLegacy
{
	
	
	public function getData(){
	
		//$obj = new stdClass;
		$arr = array();
		
		$db = JFactory::getDbo();
		
		/*Amigo restaurent */
		$sql = "SELECT introtext,images FROM #__content WHERE id=85";
		$db->setQuery($sql);
		$rs = $db->loadObject();
		
		$sql_vn = "SELECT introtext FROM #__content WHERE id=86";
		$db->setQuery($sql_vn);
		$rs_vn = $db->loadObject();
		
		$data_images = json_decode($rs->images,JSON_HEX_TAG | JSON_HEX_QUOT | JSON_HEX_AMP | JSON_UNESCAPED_UNICODE);
		$arr["wmc"]['introtext_en'] = $rs->introtext;
		$arr["wmc"]['img']       = $data_images['image_fulltext'];
		$arr["wmc"]['introtext_vn']  = $rs_vn->introtext;
		
		/*Amigo restaurent */
		$sql = "SELECT introtext,images FROM #__content WHERE id=19";
		$db->setQuery($sql);
		$rs = $db->loadObject();
		
		$sql_vn = "SELECT value FROM #__falang_content WHERE id=130";
		$db->setQuery($sql_vn);
		$rs_vn = $db->loadObject();
		
		$data_images = json_decode($rs->images,JSON_HEX_TAG | JSON_HEX_QUOT | JSON_HEX_AMP | JSON_UNESCAPED_UNICODE);
		$arr["amigo"]['introtext_en'] = $rs->introtext;
		$arr["amigo"]['img']       = $data_images['image_fulltext'];
		$arr["amigo"]['introtext_vn']  = $rs_vn->value;
		
		/*CCAD restaurent */
		$sql = "SELECT introtext,images FROM #__content WHERE id=18";
		$db->setQuery($sql);
		$rs = $db->loadObject();
		
		$sql_vn = "SELECT value FROM #__falang_content WHERE id=135";
		$db->setQuery($sql_vn);
		$rs_vn = $db->loadObject();
		
		$data_images = json_decode($rs->images,JSON_HEX_TAG | JSON_HEX_QUOT | JSON_HEX_AMP | JSON_UNESCAPED_UNICODE);
		$arr["ccad"]['introtext_en'] = $rs->introtext;
		$arr["ccad"]['img']       = $data_images['image_fulltext'];
		$arr["ccad"]['introtext_vn']  = $rs_vn->value;
		
		/*CCNH restaurent */
		$sql = "SELECT introtext,images FROM #__content WHERE id=17";
		$db->setQuery($sql);
		$rs = $db->loadObject();
		
		$sql_vn = "SELECT value FROM #__falang_content WHERE id=140";
		$db->setQuery($sql_vn);
		$rs_vn = $db->loadObject();
		
		$data_images = json_decode($rs->images,JSON_HEX_TAG | JSON_HEX_QUOT | JSON_HEX_AMP | JSON_UNESCAPED_UNICODE);
		$arr["ccnh"]['introtext_en'] = $rs->introtext;
		$arr["ccnh"]['img']       = $data_images['image_fulltext'];
		$arr["ccnh"]['introtext_vn']  = $rs_vn->value;
		
		/*dubao restaurent */
		$sql = "SELECT introtext,images FROM #__content WHERE id=20";
		$db->setQuery($sql);
		$rs = $db->loadObject();
		
		$sql_vn = "SELECT value FROM #__falang_content WHERE id=145";
		$db->setQuery($sql_vn);
		$rs_vn = $db->loadObject();
		
		$data_images = json_decode($rs->images,JSON_HEX_TAG | JSON_HEX_QUOT | JSON_HEX_AMP | JSON_UNESCAPED_UNICODE);
		$arr["ducbao"]['introtext_en'] = $rs->introtext;
		$arr["ducbao"]['img']       = $data_images['image_fulltext'];
		$arr["ducbao"]['introtext_vn']  = $rs_vn->value;
		
		/*kissho restaurent */
		$sql = "SELECT introtext,images FROM #__content WHERE id=22";
		$db->setQuery($sql);
		$rs = $db->loadObject();
		
		$sql_vn = "SELECT value FROM #__falang_content WHERE id=150";
		$db->setQuery($sql_vn);
		$rs_vn = $db->loadObject();
		
		$data_images = json_decode($rs->images,JSON_HEX_TAG | JSON_HEX_QUOT | JSON_HEX_AMP | JSON_UNESCAPED_UNICODE);
		$arr["kissho"]['introtext_en'] = $rs->introtext;
		$arr["kissho"]['img']       = $data_images['image_fulltext'];
		$arr["kissho"]['introtext_vn']  = $rs_vn->value;
		
		/*ngandinh restaurent */
		$sql = "SELECT introtext,images FROM #__content WHERE id=21";
		$db->setQuery($sql);
		$rs = $db->loadObject();
		
		$sql_vn = "SELECT value FROM #__falang_content WHERE id=155";
		$db->setQuery($sql_vn);
		$rs_vn = $db->loadObject();
		
		$data_images = json_decode($rs->images,JSON_HEX_TAG | JSON_HEX_QUOT | JSON_HEX_AMP | JSON_UNESCAPED_UNICODE);
		$arr["ngandinh"]['introtext_en'] = $rs->introtext;
		$arr["ngandinh"]['img']       = $data_images['image_fulltext'];
		$arr["ngandinh"]['introtext_vn']  = $rs_vn->value;
		
		/*tott restaurent */
		$sql = "SELECT introtext,images FROM #__content WHERE id=23";
		$db->setQuery($sql);
		$rs = $db->loadObject();
		
		$sql_vn = "SELECT value FROM #__falang_content WHERE id=160";
		$db->setQuery($sql_vn);
		$rs_vn = $db->loadObject();
		
		$data_images = json_decode($rs->images,JSON_HEX_TAG | JSON_HEX_QUOT | JSON_HEX_AMP | JSON_UNESCAPED_UNICODE);
		$arr["tott"]['introtext_en'] = $rs->introtext;
		$arr["tott"]['img']       = $data_images['image_fulltext'];
		$arr["tott"]['introtext_vn']  = $rs_vn->value;
		
		/*longtrieu restaurent */
		$sql = "SELECT introtext,images FROM #__content WHERE id=78";
		$db->setQuery($sql);
		$rs = $db->loadObject();
		
		$sql_vn = "SELECT value FROM #__falang_content WHERE id=494";
		$db->setQuery($sql_vn);
		$rs_vn = $db->loadObject();
		
		$data_images = json_decode($rs->images,JSON_HEX_TAG | JSON_HEX_QUOT | JSON_HEX_AMP | JSON_UNESCAPED_UNICODE);
		$arr["longtrieu"]['introtext_en'] = $rs->introtext;
		$arr["longtrieu"]['img']       = $data_images['image_fulltext'];
		$arr["longtrieu"]['introtext_vn']  = $rs_vn->value;
		
		/*thelong restaurent */
		$sql = "SELECT introtext,images FROM #__content WHERE id=104";
		$db->setQuery($sql);
		$rs = $db->loadObject();
		
		$sql_vn = "SELECT value FROM #__falang_content WHERE id=627";
		$db->setQuery($sql_vn);
		$rs_vn = $db->loadObject();
		
		$data_images = json_decode($rs->images,JSON_HEX_TAG | JSON_HEX_QUOT | JSON_HEX_AMP | JSON_UNESCAPED_UNICODE);
		$arr["thelong"]['introtext_en'] = $rs->introtext;
		$arr["thelong"]['img']       = $data_images['image_fulltext'];
		$arr["thelong"]['introtext_vn']  = $rs_vn->value;
		
		/*randj restaurent */
		$sql = "SELECT introtext,images FROM #__content WHERE id=117";
		$db->setQuery($sql);
		$rs = $db->loadObject();
		
		$sql_vn = "SELECT value FROM #__falang_content WHERE id=660";
		$db->setQuery($sql_vn);
		$rs_vn = $db->loadObject();
		
		$data_images = json_decode($rs->images,JSON_HEX_TAG | JSON_HEX_QUOT | JSON_HEX_AMP | JSON_UNESCAPED_UNICODE);
		$arr["randj"]['introtext_en'] = $rs->introtext;
		$arr["randj"]['img']       = $data_images['image_fulltext'];
		$arr["randj"]['introtext_vn']  = $rs_vn->value;
		
		/*cafecardinal restaurent */
		$sql = "SELECT introtext,images FROM #__content WHERE id=207";
		$db->setQuery($sql);
		$rs = $db->loadObject();
		
		$sql_vn = "SELECT value FROM #__falang_content WHERE id=1204";
		$db->setQuery($sql_vn);
		$rs_vn = $db->loadObject();
		
		$data_images = json_decode($rs->images,JSON_HEX_TAG | JSON_HEX_QUOT | JSON_HEX_AMP | JSON_UNESCAPED_UNICODE);
		$arr["cafecardinal"]['introtext_en'] = $rs->introtext;
		$arr["cafecardinal"]['img']       = $data_images['image_fulltext'];
		$arr["cafecardinal"]['introtext_vn']  = $rs_vn->value;
		
		return $arr;
	
	}
	
	public function checkForm($post){
		
		$flag = true;
		$err="";
		$arr = array();
		if(($post['restaurent'] == "0_en")||($post['restaurent'] == "0_vn")){
			$flag = false;
			$err .= JText::_('WMC_RESERVATION_RESTAURENT_ERR');
		}
		if(($post['f_name'] == "")){
			$flag = false;
			$err .= JText::_('WMC_RESERVATION_FNAME_ERR');
		}
		if(($post['l_name'] == "")){
			$flag = false;
			$err .= JText::_('WMC_RESERVATION_LNAME_ERR');
		}
		if(($post['phone'] == "")){
			$flag = false;
			$err .= JText::_('WMC_RESERVATION_PHONE_ERR');
		}
		if(($post['email'] == "")){
			$flag = false;
			$err .= JText::_('WMC_RESERVATION_EMAIL_ERR');
		}
		if(($post['date'] == "")){
			$flag = false;
			$err .= JText::_('WMC_RESERVATION_DATE_ERR');
		}
		if(($post['party_size'] == "")){
			$flag = false;
			$err .= JText::_('WMC_RESERVATION_PARTYSIZE_ERR');
		}
		
		$arr[] = $flag; $arr[] = $err;
		
		return $arr;
	}
	
	// Overwriting JView display method
	function display($tpl = null)
	{
		
		$post = $_POST;
		if(isset($post['submit'])) {
		
			$flag = $this->checkForm($post);
		
			if(!$flag[0]){
				JFactory::getApplication()->enqueueMessage($flag[1], 'error');
			}
			else {
			
				$mailer = JFactory::getMailer();
				$config = JFactory::getConfig();
				$mailer->setSender("WMC Reservation <info@wmcvietnam.com>");
				
				$email = $this->getEmail($post['restaurent']);
				//echo "<pre>";print_r($email);exit;
				//$recipient = array( 'hung.phan@wmcvietnam.com' );
				/*
				$mailer->addRecipient($email["to"]);
				$mailer->addCC($email["cc"]);		
				$mailer->setSubject('Reservation from wmcvietnam.com');
				$mailer->isHTML(true);
				$mailer->Encoding = 'base64';
				$mailer->setBody($body);
				
				$send = $mailer->Send();
				*/
				$req = "";
				if(!empty($post['req0'])){
				
					$res .= $post['req0'].", ";
				}
				if(!empty($post['req1'])){
				
					$res .= $post['req1'].", ";
				}
				if(!empty($post['req2'])){
				
					$res .= $post['req2'].", ";
				}
				$lang = JRequest::get("lang");
				if($lang == "en" || $lang == "en-gb" || $lang == "en-GB"){
					$post["time"] = $post["hours"]." Hours, ".$post["minutes"]." Minutes ".$post["am"];
				}
				else {
					$post["time"] = $post["hours"]." Giờ, ".$post["minutes"]." Phút, ". ($post["am"] == "AM" ? "buổi sáng": "buổi chiều");
				}
				$res = substr($res,0,-2);
				$array_key = array('{prefix}','{f_name}','{l_name}','{phone}','{email}','{party_size}','{date}','{time}','{req}','{special}');
				$array_replace = array($post['prefix'],$post['f_name'],$post['l_name'],$post['phone'],$post['email'],$post['party_size'],date("d-m-Y",strtotime($post['date'])),$post['time'],$res,"<pre style='font-size: 12px;'>".$post['special']."</pre>");
				
				$file = $this->getTemplateSendToUser($post['restaurent']);
				$res = $post['restaurent'];
				
				$emailBody = str_ireplace($array_key,$array_replace,$file[0]);
				
				$subject = $file[1];
				$default_fromname = 'WMC Group';
				$default_fromemail = 'info@wmcvietnam.com';

				$header = "mine-version: 1.0" . "\r\n";
				$header .= "content-type:text/html;charset=utf-8" . "\r\n";
				// $header .= 'from: '.count($email["fromname"]) ? $default_fromname : $default_fromname .' Reservation<info@wmcvietnam.com>' . "\r\n";

				if(count($email["fromname"])){
					for($i=0;$i<count($email["fromname"]);$i++){		
						if($email["fromname"][$i]  != ''){				
							$header .= 'from: '.$email["fromname"][$i];
						}else{
							$header .= 'from: '.$default_fromname;
						}
					}
				}else{
					$header .= 'from: '.$default_fromname;
				}

				if(count($email["fromemail"])){
					for($i=0;$i<count($email["fromemail"]);$i++){
						if($email["fromemail"][$i]  != ''){
							$header .= ' <'.$email["fromemail"][$i].'>'."\r\n";
							$header .= 'Reply-to:'. ' <'.$email["fromemail"][$i].'>'."\r\n";
						}else{
							$header .= ' <'.$default_fromemail.'>'."\r\n";
							$header .= 'Reply-to:'.$default_fromemail."\r\n";
						}						
						
					}
				}else{
					$header .= ' <'.$default_fromemail.'>'."\r\n";
				}
				
				mail($post['email'], $subject, $emailBody, $header);
				/*if(count($email["bcc"])){
					for($i=0;$i<count($email["cc"]);$i++){
						
						mail($email["bcc"][$i], $subject, $emailBody, $header);
					}
				}
				if(!empty($email["bcc"])){
					mail(implode(",",$email["bcc"]), $subject, $emailBody, $header);
				}
				*/
				if(count($email["cc"])){
					for($i=0;$i<count($email["cc"]);$i++){
						
						$header .= 'cc: '.$email["cc"][$i]. "\r\n";
					}
				}
				if(count($email["bcc"])){
					for($i=0;$i<count($email["bcc"]);$i++){
						
						$header .= 'bcc: '.$email["bcc"][$i]. "\r\n";
					}
				}
				//echo "<pre>";print_r($email);exit;
				//$header .= 'bcc: '.$post['email']. "\r\n";
				//echo $header;exit;
				$send = mail(implode(",",$email["to"]), $subject, $emailBody, $header);
				

				$req = array();
				
				$req = array($post['req0'],$post['req1'],$post['req2'],$post['req3'],$post['req4']);
				
				$post["special_req"] = serialize($req);
				
				date_default_timezone_set('Asia/Ho_Chi_Minh');
				$post["created_date"] = date("Y-m-d H:i:s");
				
				if ( $send !== true ) {?>
					<div class="success_notice_box">
						<?php echo JText::_('WMC_RESERVATION_SUBMIT_SUCCESS'); ?>
					</div>
					<?php
					JFactory::getApplication()->enqueueMessage("Error send email", 'error');
					$post["send_email"] = 0;
				
				} else {?>					
					<div class="success_notice_box">
						<?php echo JText::_('WMC_RESERVATION_SUBMIT_SUCCESS'); ?>
					</div>					
					<?php $post["send_email"] = 1;
					JFactory::getApplication()->enqueueMessage(JText::_('WMC_RESERVATION_SUCCESS_SEND_MAIL'),"");
				}
			
			$this->saveReservation($post);
			
			}
			
			
		}
		
		$arr = $this->getData();
		$this->assignRef('arr', $arr);
		parent::display($tpl);
	}
	
	public function getTemplateSendToUser($restaurent){
	
		if(empty($restaurent) || ($restaurent == "0_en") || ($restaurent == "0_vn")) return ;
		
		$file = array();
		
		switch ($restaurent) {
			case "1_en":
				$file[] = file_get_contents(JURI::root().'components/com_wmcreservation/html/amigo_en.html');
				$file[] = "Amigo Grill Restaurant - Reservation Request";
				break;
			case "2_en":
				$file[] = file_get_contents(JURI::root().'components/com_wmcreservation/html/ccad_en.html');
				$file[] = "Café Central An Dong Restaurant - Reservation Request";
				break;
			case "3_en":
				$file[] = file_get_contents(JURI::root().'components/com_wmcreservation/html/ccnh_en.html');
				$file[] = "Café Central Nguyen Hue Restaurant - Reservation Request";
				break;
			case "4_en":
				$file[] = file_get_contents(JURI::root().'components/com_wmcreservation/html/ducbao_en.html');
				$file[] = "Gartenstadt Restaurant - Reservation Request";
				break;
			case "5_en":
				$file[] = file_get_contents(JURI::root().'components/com_wmcreservation/html/kissho_en.html'); 
				$file[] = "Kissho Restaurant - Reservation Request";
				break;
			case "6_en":
				$file[] = file_get_contents(JURI::root().'components/com_wmcreservation/html/ngandinh_en.html');  
				$file[] = "Ngan Dinh Restaurant - Reservation Request";
				break;
			case "7_en":
				$file[] = file_get_contents(JURI::root().'components/com_wmcreservation/html/tott_en.html');  
				$file[] = "Top of the Town Bar & Restaurant - Reservation Request";
				break;
			case "8_en":
				$file[] = file_get_contents(JURI::root().'components/com_wmcreservation/html/longtrieu_en.html');	
				$file[] = "The Royal Pavilion - Reservation Request";
				break;
			case "9_en":
				$file[] = file_get_contents(JURI::root().'components/com_wmcreservation/html/thelong_en.html');  
				$file[] = "The Long @ Times Square - Reservation Request";
				break;
			case "10_en":
				$file[] = file_get_contents(JURI::root().'components/com_wmcreservation/html/randj_en.html');	
				$file[] = "R and J Italian Restaurant - Reservation Request";
				break;
			case "11_en":
				$file[] = file_get_contents(JURI::root().'components/com_wmcreservation/html/cafecardinal_en.html');	
				$file[] = "Cafe Cardinal Restaurant - Reservation Request";
				break;
				
			case "1_vn":
				$file[] = file_get_contents(JURI::root().'components/com_wmcreservation/html/amigo_vn.html');
				$file[] = "Xác nhận đặt bàn tại nhà hàng Amigo";
				break;
			case "2_vn":
				$file[] = file_get_contents(JURI::root().'components/com_wmcreservation/html/ccad_vn.html');
				$file[] = "Xác nhận đặt bàn tại nhà hàng Café Central An Đông";
				break;
			case "3_vn":
				$file[] = file_get_contents(JURI::root().'components/com_wmcreservation/html/ccnh_vn.html');
				$file[] = "Xác nhận đặt bàn tại nhà hàng Café Central Nguyễn Huệ";
				break;
			case "4_vn":
				$file[] = file_get_contents(JURI::root().'components/com_wmcreservation/html/ducbao_vn.html');
				$file[] = "Xác nhận đặt bàn tại nhà hàng Đức Bảo";
				break;
			case "5_vn":
				$file[] = file_get_contents(JURI::root().'components/com_wmcreservation/html/kissho_vn.html');
				$file[] = "Xác nhận đặt bàn tại nhà hàng Kissho";
				break;	
			case "6_vn":
				$file[] = file_get_contents(JURI::root().'components/com_wmcreservation/html/ngandinh_vn.html'); 
				$file[] = "Xác nhận đặt bàn tại nhà hàng Ngân Đình";
				break;
			case "7_vn":
				$file[] = file_get_contents(JURI::root().'components/com_wmcreservation/html/tott_vn.html');
				$file[] = "Xác nhận đặt bàn tại nhà hàng Top of the Town";
				break;
			case "8_vn":
				$file[] = file_get_contents(JURI::root().'components/com_wmcreservation/html/longtrieu_vn.html');
				$file[] = "Xác nhận đặt bàn tại nhà hàng Long Triều";
				break;
			case "9_vn":
				$file[] = file_get_contents(JURI::root().'components/com_wmcreservation/html/thelong_vn.html');
				$file[] = "Xác nhận đặt bàn tại nhà hàng The Long @ Times Square";
				break;
			case "10_vn":
				$file[] = file_get_contents(JURI::root().'components/com_wmcreservation/html/randj_vn.html');
				$file[] = "Xác nhận đặt bàn tại nhà hàng Ý R and J";
				break;
			case "11_vn":
				$file[] = file_get_contents(JURI::root().'components/com_wmcreservation/html/cafecardinal_vn.html');
				$file[] = "Xác nhận đặt bàn tại nhà hàng Cafe Cardinal";
				break;	
		}
		return $file;
		
	}
	public function saveReservation($post){
		
		$db = JFactory::getDbo();
		$obj = new stdClass;	
		$obj->restaurent =  $this->getRestaurentName($post['restaurent']);
		$obj->prefix = $post['prefix'];
		$obj->fname = $post['f_name'];
		$obj->lname = $post['l_name'];
		$obj->phone = $post['phone'];
		$obj->email = $post['email'];
		$obj->time = $post['time'];
		$obj->date = date("Y-m-d",strtotime($post['date']));
		$obj->party_size = $post['party_size'];
		$obj->special_req = $post['special_req'];
		$obj->special = $post['special'];
		$obj->created_date = $post['created_date'];
		$obj->send_email = $post['send_email'];
		$db ->insertObject('#__wmcreservation', $obj); 
		
	}
	
	public function getRestaurentName($restaurent) {
		
		if(empty($restaurent) || ($restaurent == "0_en") || ($restaurent == "0_vn")) return ;
		$name = "";
		
		switch ($restaurent) {
			case "1_en":
				$name = "Amigo Grill Restaurant"; break;
			case "2_en":
				$name = "Café Central An Dong"; break;
			case "3_en":
				$name = "Café Central Nguyen Hue"; break;
			case "4_en":
				$name = "Gartenstadt Restaurant"; break;
			case "5_en":
				$name = "Kissho Restaurant"; break;
			case "6_en":
				$name = "Ngan Dinh Restaurant"; break;
			case "7_en":
				$name = "Top of the Town Bar & Restaurant"; break;
			case "8_en":
				$name = "The Royal Pavilion"; break;
			case "9_en":
				$name = "The Long @ Times Square"; break;
			case "10_en":
				$name = "R and J Italian Restaurant"; break;
			case "11_en":
				$name = "Cafe Cardinal Restaurant"; break;
				
				
			case "1_vn":
				$name = "Nhà hàng Amigo"; break;
			case "2_vn":
				$name = "Café Central An Đông"; break;
			case "3_vn":
				$name = "Café Central Nguyễn Huệ"; break;
			case "4_vn":
				$name = "Nhà hàng Đức Bảo"; break;
			case "5_vn":
				$name = "Nhà hàng Kissho"; break;	
			case "6_vn":
				$name = "Nhà hàng Ngân Đình"; break;
			case "7_vn":
				$name = "Nhà hàng Top of the Town"; break;
			case "8_vn":
				$name = "Nhà hàng Long Triều"; break;
			case "9_vn":
				$name = "Nhà hàng The Long @ Times Square"; break;
			case "10_vn":
				$name = "Nhà hàng Ý R and J"; break;
			case "11_vn":
				$name = "Nhà hàng Cafe Cardinal"; break;

				
		}
		return $name;
		
	}
	public function getEmail($restaurent) {
		
		if(empty($restaurent) || ($restaurent == "0_en") || ($restaurent == "0_vn")) return ;
		
		$db = JFactory::getDbo();
		$email = array();
		if($restaurent == "1_en"||$restaurent == "1_vn"){
			
			$sql = "SELECT fromname,fromemail,emailto,emailcc,emailbcc FROM #__content WHERE id=19";
			$db->setQuery($sql);
			$rs = $db->loadObject();
			$email["fromname"] = explode(",",$rs->fromname);
			$email["fromemail"] = explode(",",$rs->fromemail);
			$email["to"] = explode(",",$rs->emailto);
			$email["cc"] = explode(",",$rs->emailcc);
			$email["bcc"] = explode(",",$rs->emailbcc);

			return $email;
		}
		else if($restaurent == "2_en"||$restaurent == "2_vn"){
			
			$sql = "SELECT fromname,fromemail,emailto,emailcc,emailbcc FROM #__content WHERE id=18";
			$db->setQuery($sql);
			$rs = $db->loadObject();
			$email["fromname"] = explode(",",$rs->fromname);
			$email["fromemail"] = explode(",",$rs->fromemail);
			$email["to"] = explode(",",$rs->emailto);
			$email["cc"] = explode(",",$rs->emailcc);
			$email["bcc"] = explode(",",$rs->emailbcc);
			return $email;
		}
		else if($restaurent == "3_en"||$restaurent == "3_vn"){
			
			$sql = "SELECT fromname,fromemail,emailto,emailcc,emailbcc FROM #__content WHERE id=17";
			$db->setQuery($sql);
			$rs = $db->loadObject();
			$email["fromname"] = explode(",",$rs->fromname);
			$email["fromemail"] = explode(",",$rs->fromemail);
			$email["to"] = explode(",",$rs->emailto);
			$email["cc"] = explode(",",$rs->emailcc);
			$email["bcc"] = explode(",",$rs->emailbcc);
			return $email;
		}
		else if($restaurent == "4_en"||$restaurent == "4_vn"){
			
			$sql = "SELECT fromname,fromemail,emailto,emailcc,emailbcc FROM #__content WHERE id=20";
			$db->setQuery($sql);
			$rs = $db->loadObject();
			$email["fromname"] = explode(",",$rs->fromname);
			$email["fromemail"] = explode(",",$rs->fromemail);
			$email["to"] = explode(",",$rs->emailto);
			$email["cc"] = explode(",",$rs->emailcc);
			$email["bcc"] = explode(",",$rs->emailbcc);
			return $email;
		}
		else if($restaurent == "5_en"||$restaurent == "5_vn"){
			
			$sql = "SELECT fromname,fromemail,emailto,emailcc,emailbcc FROM #__content WHERE id=22";
			$db->setQuery($sql);
			$rs = $db->loadObject();
			$email["fromname"] = explode(",",$rs->fromname);
			$email["fromemail"] = explode(",",$rs->fromemail);
			$email["to"] = explode(",",$rs->emailto);
			$email["cc"] = explode(",",$rs->emailcc);
			$email["bcc"] = explode(",",$rs->emailbcc);
			return $email;
		}
		else if($restaurent == "6_en"||$restaurent == "6_vn"){
			
			$sql = "SELECT fromname,fromemail,emailto,emailcc,emailbcc FROM #__content WHERE id=21";
			$db->setQuery($sql);
			$rs = $db->loadObject();
			$email["fromname"] = explode(",",$rs->fromname);
			$email["fromemail"] = explode(",",$rs->fromemail);
			$email["to"] = explode(",",$rs->emailto);
			$email["cc"] = explode(",",$rs->emailcc);
			$email["bcc"] = explode(",",$rs->emailbcc);
			return $email;
		}
		else if($restaurent == "7_en"||$restaurent == "7_vn"){
			
			$sql = "SELECT fromname,fromemail,emailto,emailcc,emailbcc FROM #__content WHERE id=23";
			$db->setQuery($sql);
			$rs = $db->loadObject();
			$email["fromname"] = explode(",",$rs->fromname);
			$email["fromemail"] = explode(",",$rs->fromemail);
			$email["to"] = explode(",",$rs->emailto);
			$email["cc"] = explode(",",$rs->emailcc);
			$email["bcc"] = explode(",",$rs->emailbcc);
			return $email;
		}
		else if($restaurent == "8_en"||$restaurent == "8_vn"){
			
			$sql = "SELECT fromname,fromemail,emailto,emailcc,emailbcc FROM #__content WHERE id=78";
			$db->setQuery($sql);
			$rs = $db->loadObject();
			$email["fromname"] = explode(",",$rs->fromname);
			$email["fromemail"] = explode(",",$rs->fromemail);
			$email["to"] = explode(",",$rs->emailto);
			$email["cc"] = explode(",",$rs->emailcc);
			$email["bcc"] = explode(",",$rs->emailbcc);
			return $email;
		}
		else if($restaurent == "9_en"||$restaurent == "9_vn"){
			
			$sql = "SELECT fromname,fromemail,emailto,emailcc,emailbcc FROM #__content WHERE id=104";
			$db->setQuery($sql);
			$rs = $db->loadObject();
			$email["fromname"] = explode(",",$rs->fromname);
			$email["fromemail"] = explode(",",$rs->fromemail);
			$email["to"] = explode(",",$rs->emailto);
			$email["cc"] = explode(",",$rs->emailcc);
			$email["bcc"] = explode(",",$rs->emailbcc);
			return $email;
		}
		else if($restaurent == "10_en"||$restaurent == "10_vn"){
			
			$sql = "SELECT fromname,fromemail,emailto,emailcc,emailbcc FROM #__content WHERE id=117";
			$db->setQuery($sql);
			$rs = $db->loadObject();
			$email["fromname"] = explode(",",$rs->fromname);
			$email["fromemail"] = explode(",",$rs->fromemail);
			$email["to"] = explode(",",$rs->emailto);
			$email["cc"] = explode(",",$rs->emailcc);
			$email["bcc"] = explode(",",$rs->emailbcc);
			return $email;
		}
		else if($restaurent == "11_en"||$restaurent == "11_vn"){
			
			$sql = "SELECT fromname,fromemail,emailto,emailcc,emailbcc FROM #__content WHERE id=207";
			$db->setQuery($sql);
			$rs = $db->loadObject();
			$email["fromname"] = explode(",",$rs->fromname);
			$email["fromemail"] = explode(",",$rs->fromemail);
			$email["to"] = explode(",",$rs->emailto);
			$email["cc"] = explode(",",$rs->emailcc);
			$email["bcc"] = explode(",",$rs->emailbcc);
			return $email;
		}
		
		
		return true;
		
	}
	
}